<?php
error_reporting(E_ALL);
date_default_timezone_set("Europe/London");
ini_set('display_errors', '1');

$topdirectory="../MSWebGUI";
include $topdirectory.'/FileList.php';

$topdirectory="../Classes";
include $topdirectory.'/FileList.php';

$xml = simplexml_load_file('../config/config.xml');
$databaseXML = $xml->Database;
$database = new Database($databaseXML->Server,$databaseXML->Database,$databaseXML->Username,$databaseXML->Password);

$sql = "SELECT * from ViewedResources ORDER BY ViewedWhen DESC LIMIT 0,".$_GET['end'];
$database->ExecuteSQL($sql);
$html = "<table>\n";
while($row=$database->getRow())
{
	$database1 = $database->recopy();

	$resource = new Resource($database,$row['ResourceID']);
	
	// get user
	$sql1 = "SELECT LongName from Users where UserID = ".$row['UserID'];
	$database1->ExecuteSQL($sql1);
	$row2 = $database1->getRow();
//			print_r($row2);
	
	$date = new DateTime($row['ViewedWhen']);
	
	$filename = "";
	if ($row['PhysicalFileNumber']!=0)
		{
			// get filename
			$database2 = $database->recopy();
			$sql2 = "SELECT FSFileName from Files where PhysicalFileNumber = ".$row['PhysicalFileNumber'];
			$database2->ExecuteSQL($sql2);
			$row3=$database2->getRow();
			$filename = " (".$row3['FSFileName'].") ";
		}
	
	$html .= "<tr><td style=\"width:140px;\">".
		$date->format("D j M Y H:i")."</td><td style=\"width:100px;\">".
		$row2['LongName']."</td><td style=\"width:250px;\">".
//				$row1['LongName']."</td><td style=\"width:250px;\">".
		"<a href=\"javascript:OnClickSummary('".$resource->getResourceID()."');\">".
		"(".$resource->getResourceID().") ".
		$resource->getResourceTitle().$filename."</a></td></tr>\n";
}

$html .= "</table>\n";

echo $html;



?>